package com.example.license.controller;

import com.example.license.service.LicenseService;
import com.example.license.service.OrganizationService;
import com.example.model.License;
import com.example.model.Organization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LicenseController {
    @Autowired
    private LicenseService licenseService;

    @Autowired
    private OrganizationService organizationService;

    @GetMapping("/{id}")
    public License getLicenseById(@PathVariable int id){
        return licenseService.getLicenseById(id);
    }

    @GetMapping("/")
    public Iterable<License> index(){
        return licenseService.getAllLicense();
    }

    @GetMapping("/{clientType}/{id}")
    public Map getFullLicenseById(@PathVariable String clientType, @PathVariable int id){
        Map<String, Object> map = new HashMap<>();
        License license = licenseService.getLicenseById(id);
        Organization organization = organizationService.getOrganizationById(clientType, license.getOrgId());
        map.put("license", license);
        map.put("organization", organization);
        return map;
    }


}
